//自提出库
$(function(){
	//搜索
	$('.searchBar').click(function(){
		var thisform=$(this).parent('form');
		var order_no=thisform.find('input[name=order_no]').val();
		var user_name=thisform.find('input[name=user_name]').val();
		var user_phone=thisform.find('input[name=user_phone]').val();
		var is_delivery=thisform.find('input[name=is_delivery]').val();
		$('#owndeliveryDatagrid').datagrid('options').pageNumber=1;//设置页码初始值为1
		$('#owndeliveryDatagrid').datagrid({
			queryParams:{
				user_phone:user_phone,
				order_no:order_no,
				user_name:user_name,
				is_delivery:1
			}
		});
	})
	
	//出库
	$('.sumitBar').click(function(){
		var thisform=$(this).parent('form');
		var delivery_code=thisform.find('input[name=delivery_code]').val();
		$.ajax({
            type:"POST",
            url:outboundOrderownUrl,
			data:{delivery_code:delivery_code},
            success: function(result){
				if(result.status){
					$('#owndeliveryDatagrid').datagrid('reload');
				}else{
					$.messager.alert('错误提示',result.message,'error');
				}
                
            }
        });
		
	})
	$('#owndeliveryDatagrid').datagrid({
		url:getowndeliveryUrl,
		title:'订单列表',
		fitColumns:true,
		rownumbers:true,
		pageSize:25,
		pageNumber:1,
		pageList:[5,10,15,20,25,30,40,50],
		columns:[[
		{field:'id',title:'id',checkbox:true},
		{field:'ids',title:'',
			formatter:function(value,row,index){
				return '<a target="_blank" href="'+outboundPrinterUrl+'&order=Pushorder&orderdetail=Pushordergoods&id='+value+'&outbound=1">出库单</a>';
			}
		},
		{field:'order_no',title:'订单编码',sortable:true},
		{field:'delivery_code',title:'提货码'},
		{field:'user_name',title:'客户姓名'},
		{field:'user_phone',title:'联系电话'},
		{field:'user_idcard',title:'身份证'},
		{field:'user_address',title:'客户详细地址'},
		{field:'logistics_no',title:'物流单号'},
		{field:'logiscompany_name',title:'物流企业名称'},
		{field:'is_delivery',title:'已出库',
			formatter:function(value,row,index){
				if (value==0){
					return "否";
				} else {
					return "是";
				}
			}
		}
		]],
		onLoadError:function(data){
			var info=eval('('+data.responseText+')');
			$.messager.confirm('错误提示',info.message,function(r){
				var tab=$('#Tabs').tabs('getSelected');
				var index=$('#Tabs').tabs('getTabIndex',tab);
				$('#Tabs').tabs('close',index);
			});
		},
		onLoadSuccess:function(){
			//回车
			$('#owndelivery_KeyDown').textbox('textbox').keydown(function (e) {
		        if (e.keyCode == 13) {
		           $('.sumitBar').click();
		        }
		    });
		},
		rowStyler:function(index,row){
			if (row.color==0){
				return 'background-color:pink;color:blue;font-weight:bold;';
			}
		},
		pagination:true,
		fit:true,
	});
});
owndeliveryObj={
	showAdvanceBar:function(){
		$('#owndeliveryDatagrid').datagrid({ queryParams:{show_advance:1}});
	},
	showAll:function(){
		$('#owndeliveryDatagrid').datagrid({ queryParams:''});
	}
}